package com.dsbj.icardservice.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsbj.icardservice.entity.SerialNumber;
import com.dsbj.icardservice.mapper.EmployeeMapper;
import com.dsbj.icardservice.mapper.SerialNumberMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author cjw 2019-09-25
 */
@Service
@Transactional
public class SerialNumberService extends ServiceImpl<SerialNumberMapper, SerialNumber> {
	
	@Resource
	private SerialNumberMapper serialNumberMapper;
	
	
	//存储过程的调用
	public List<String> p1(Map<String, Object> map1) {
		return serialNumberMapper.p1(map1);
	}
	
	//根据serial_number查询
	public SerialNumber findBySerialNumber(String serialNumber) {
		return serialNumberMapper.findBySerialNumber(serialNumber);
	}
	
	/**
	 * 根据serialNumber,lengthA产生新的序列数字resultA，更新对应的记录，并返回新的单据编号。
	 * 返回的单据编号的格式为：(serialNumber+resultA).toUpperCase()。
	 *
	 * @param
	 * @return
	 * @author cjw 2019-09-06
	 */
	public String generateBillno(String serialNumber, int lengthA) {
		//调用存储过程p1
		Map<String, Object> map_input = new HashMap<>();
		map_input.put("str2", serialNumber);
		map_input.put("long2", lengthA);
		p1(map_input);
		//产生新单据编号
		String resultA = map_input.get("no1").toString();
		String billno = null;
		billno = (serialNumber + resultA).toUpperCase();
		return billno;
	}
	
	
	
}
